package com.lagou.model;

import com.lagou.Exception.AgeException;
import com.lagou.Exception.IdException;

import java.util.Objects;

public class User implements java.io.Serializable {
    private static final long serialVersionUID = -1225113970581096678L;

    /**
     * 学号
     */
    private Integer id;
    /**
     * 年龄
     */
    private Integer age;
    /**
     * 姓名
     */
    private String name;
    private String username;
    private String password;

    /**
     * 成绩分数
     */
    private Integer grade;

    public Integer getGrade() {
        return grade;
    }

    public void setGrade(Integer grade) {
        this.grade = grade;
    }

    public User() {
    }

    public User(String username, String password) {
        this.username = username;
        this.password = password;
    }

    public String getUsername() {
        return username;
    }

    public void setUsername(String username) {
        this.username = username;
    }

    public String getPassword() {
        return password;
    }

    public void setPassword(String password) {
        this.password = password;
    }

    public Integer getId() {
        return id;
    }

    public void setId(Integer id) throws IdException {
        if (id < 0) {
            throw new IdException("您所输入的学号不合理，请重新输入");
        }
        this.id = id;
    }

    public Integer getAge() {
        return age;
    }

    public void setAge(Integer age) throws AgeException {
        if (age < 0 || age > 150) {
            throw new AgeException("您所输入的年龄不合理，请重新输入");
        }
        this.age = age;

    }

    public String getName() {
        return name;
    }

    public void setName(String name) {
        this.name = name;
    }

    @Override
    public boolean equals(Object o) {
        if (this == o) return true;
        if (o == null || getClass() != o.getClass()) return false;
        User user = (User) o;
        return Objects.equals(id, user.id) &&
                Objects.equals(age, user.age) &&
                Objects.equals(name, user.name) &&
                Objects.equals(username, user.username) &&
                Objects.equals(password, user.password) &&
                Objects.equals(grade, user.grade);
    }

    @Override
    public String toString() {
        return "User{" +
                "id=" + id +
                ", age=" + age +
                ", name='" + name + '\'' +
                ", username='" + username + '\'' +
                ", password='" + password + '\'' +
                ", grade=" + grade +
                '}';
    }

    @Override
    public int hashCode() {

        return Objects.hash(id, age, name, username, password, grade);
    }

}
